﻿using DevExpress.XtraEditors.Repository;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.CRM
{
    public partial class FormCRM客户详细资料 : DevExpress.XtraEditors.XtraForm
    {
        private GridEditorCollection gridEditors;
        public FormCRM客户详细资料()
        {
            InitializeComponent();
            this.gridEditors = new GridEditorCollection();
            InitInplaceEditors();
            this.gridControl客户基本信息.DataSource = gridEditors;
        }

        void InitInplaceEditors()
        {
            this.gridEditors.Add(this.repositoryItemTextEdit1, "姓名", "");
            this.gridEditors.Add(this.repositoryItemTextEdit2, "性别", "");
            this.gridEditors.Add(this.repositoryItemTextEdit3, "年龄", "");
            this.gridEditors.Add(this.repositoryItemTextEdit4, "电话", "");
            this.gridEditors.Add(this.repositoryItemTextEdit5, "地址", "");
            this.gridEditors.Add(this.repositoryItemTextEdit6, "客户来源", "");
            this.gridEditors.Add(this.repositoryItemTextEdit7, "体型特征", "");
            this.gridEditors.Add(this.repositoryItemTextEdit8, "标准体/特体", "");
            this.gridEditors.Add(this.repositoryItemMemoExEdit1, "喜好", "");
        }

        private void gridView2_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
        {
            if (e.Column == this.gridEditorValue)
            {
                GridEditorItem item = gridView1.GetRow(e.RowHandle) as GridEditorItem;
                if (item != null) e.RepositoryItem = item.RepositoryItem;
            }
        }
    }

    public class GridEditorItem
    {
        string fName;
        object fValue;
        RepositoryItem fRepositoryItem;

        public GridEditorItem(RepositoryItem fRepositoryItem, string fName, object fValue)
        {
            this.fRepositoryItem = fRepositoryItem;
            this.fName = fName;
            this.fValue = fValue;
        }
        public string Name { get { return this.fName; } }
        public object Value { get { return this.fValue; } set { this.fValue = value; } }
        public RepositoryItem RepositoryItem { get { return this.fRepositoryItem; } }
    }

    class GridEditorCollection : ArrayList
    {
        public GridEditorCollection()
        {
        }
        public new GridEditorItem this[int index] { get { return base[index] as GridEditorItem; } }
        public void Add(RepositoryItem fRepositoryItem, string fName, object fValue)
        {
            base.Add(new GridEditorItem(fRepositoryItem, fName, fValue));
        }
    }

}
